package jinyilw.swing.visuals.text;

import jinyilw.swing.FontTools;
import jinyilw.swing.i18n.ICSetting;
import jinyilw.swing.i18n.IString;
import jinyilw.swing.visuals.border.RTitledBorder;

import javax.swing.JScrollPane;
import javax.swing.border.TitledBorder;
import java.awt.Color;
import java.awt.Font;

public class RCTextPane extends JScrollPane
{
	private static final long serialVersionUID = 1426105354548989576L;
	private final RCEditorPane editorPane = new RCEditorPane();
	private RTitledBorder titledBorder;

	public RCTextPane()
	{
		super();
		setViewportView(editorPane);
	}

	public RCTextPane(String text)
	{
		super();
		setViewportView(editorPane);
		editorPane.setText(text);
	}

	public RCTextPane(String text, String title)
	{
		super();
		setViewportView(editorPane);
		editorPane.setText(text);
		setTitle(title);
	}

	public RCTextPane(int vsbPolicy, int hsbPolicy)
	{
		super(vsbPolicy, hsbPolicy);
		setViewportView(editorPane);
	}

	public RCEditorPane getEditorPane()
	{
		return editorPane;
	}

	@Override
	public void setFont(Font font)
	{
		if (editorPane != null)
			editorPane.setFont(font);
	}

	public void setXAlignment(int alignment)
	{
		editorPane.setXAlignment(alignment);
	}

	public void setText(String text)
	{
		editorPane.setText(text);
	}

	public void setText(IString iString)
	{
		editorPane.setText(iString);
	}

	public void setTitle(String title)
	{
		createTitle();
		titledBorder.setTitle(title);
	}

	public void setITitle(ICSetting iTitle)
	{
		createTitle();
		titledBorder.setI18nTitle(iTitle);
	}

	public void setTransparent(boolean b)
	{
		editorPane.setTransparent(b);
	}

	private void createTitle()
	{
		if (titledBorder == null)
		{
			titledBorder = new RTitledBorder(null, "",
					TitledBorder.DEFAULT_JUSTIFICATION,
					TitledBorder.DEFAULT_POSITION, FontTools.getCustomFont(13),
					Color.CYAN);
			setBorder(titledBorder);
		}
	}
}
